-----------------------------------------------------------------------------
-- |
-- Maintainer  :  2LT Team
--
-- Example of transformation in the presence of schema constraints.
--
-----------------------------------------------------------------------------

{-# OPTIONS -fglasgow-exts #-}

module Data.Transform.ConstraintsHUnit where

import HUnit

-- import Rel
-- import RelTransf
import Data.Transform.Type
import Data.Transform.Coupled
-- import Data.Transform.Constraints
-- import TypeTransf
-- import HierRelTransf

import Data.Set as Set
import Data.Map as Map

-----------------------------------------------------------------------------

main = runTestTT . TestList . Prelude.map TestCase $ 
    [ testList2Map
    , testList2MapPropagate
    , testImdb
    ]

-----------------------------------------------------------------------------
-- * Testing basic rules

testList2Map = do
  let format     = List Bool
  let (Just vw)  = listmap format
  let actual     = getType vw
  let expected   = DynType (Map Int Bool)
  assertEqual "List should be transformed to Map" expected actual

testList2MapPropagate = do
  let format     = TInv (List Bool) (FUN "inv" (const True))
  let (Just vw)  = (or_propagate listmap) format
  let actual     = getType vw
  let expected   = DynType (TInv (Map Int Bool) (FUN "inv" (const True) .*. ELEMS))
  assertEqual "List should be transformed to Map" expected actual

-----------------------------------------------------------------------------
-- * Type synonyms for the example schema

-- | Haskell definition
type Imdb    = (Actors, Show')
type Show'   = Map (Year, Title) ([Review], Either Movie Series)
type Movie   = ([(Country, Value)], Director)
type Series  = Map Year [Episode]
type Episode = (Number, Maybe Director) 
type Actors  = Map Name Played
type Played  = Map ((Year, Title), Role) [Award]

type Year     = Int
type Title    = String
type Review   = String
type Country  = String
type Value    = Int
type Director = String
type Number   = Int
type Name     = String
type Role     = String
type Award    = String

-- | GADT Type definition
{-
imdb :: (Type Imdb)
imdb     = TInv (Prod actors show') imdb_inv
imdb_inv = RInc (RComp (RSetMap FST) (RComp RFuse (RComp (RSetMap RDom) (RComp RRng FST))))
                (RComp RDom SND)

show'   = Map (Prod Int String) (Prod (List String) (Either movie series))
movie   = Prod (List (Prod String Int)) String
series  = Map Int (List episode)
episode = Prod Int (Maybe String)
actors  = Map String played
played  = Map (Prod (Prod Int String) String) (List String)
-- Pablo version: 
-- played = List (Prod Int (Prod String (Prod String (List String))))
-}

-- | Type representation for the example schema
imdb     = TInv (Prod actors show') imdb_inv
imdb_inv = (SET FST .*. SETFUSE .*. SET DOM .*. RNG .*. FST) .=<. (DOM .*. SND)
show'   = Map (Prod (TVar "Year") (TVar "Title")) (Prod (List (TVar "Review")) (Either movie series))
movie   = Prod (List (Prod (TVar "Country") (TVar "Value"))) (TVar "Director")
series  = Map (TVar "Year") (List episode)
episode = Prod (TVar "Number") (Maybe (TVar "Director"))
actors  = Map (TVar "Name") played
played  = Map (Prod (Prod (TVar "Year") (TVar "Title")) (TVar "Role")) (List (TVar "Award"))

testImdb = do
  putStrLn "\nWARNING: this test takes a long time!!"
  let (Just vw)  = flattenInv imdb
  let actual     = getType vw
  let expected   = DynType Int
  putStrLn (applyDynType (showDB tables) actual)
  assertEqual "Imdb should be flattened" expected actual

tables = [ "playeds", "awards" , "actors", "shows", "reviews", "seasons", "episodes", "series", "movies", "boxoffices" ]

applyDynType :: (forall a . Type a -> b) -> DynType -> b
applyDynType f (DynType t) = f t

{-

imdbRelNoSimplify = (TInv (Prod (Map (Prod (Prod (Prod (TVar "Name" ) (TVar "Year" )) (TVar "Title" )) (TVar "Role" )) One) (Prod (Map (Prod (Prod (Prod (Prod (TVar "Name" ) (TVar "Year" )) (TVar "Title" )) (TVar "Role" )) Int) (TVar "Award" )) (Prod (Map (TVar "Name" ) One) (Prod (Map (Prod (TVar "Year" ) (TVar "Title" )) One) (Prod (Map (Prod (Prod (TVar "Year" ) (TVar "Title" )) Int) (TVar "Review" )) (Prod (Map (Prod (Prod (TVar "Year" ) (TVar "Title" )) (TVar "Year" )) One) (Prod (Map (Prod (Prod (Prod (TVar "Year" ) (TVar "Title" )) (TVar "Year" )) Int) (Prod (TVar "Number" ) (Maybe (TVar "Director" )))) (Prod (Map (Prod (TVar "Year" ) (TVar "Title" )) One) (Prod (Map (Prod (TVar "Year" ) (TVar "Title" )) (TVar "Director" )) (Map (Prod (Prod (TVar "Year" ) (TVar "Title" )) Int) (Prod (TVar "Country" ) (TVar "Value" )))))))))))) (RAnd (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RInc (RComp (RSetMap FST) (RComp RDom SND)) (RComp RDom FST)) SND) SND) SND) SND) SND) SND) SND) SND) (RAnd (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RInc (RComp (RSetMap FST) (RComp RDom SND)) (RComp RDom FST)) (RProdMap (RDomMap RAssocl) RId)) (RProdMap RId (RDomMap RAssocl))) (RProdMap RId (RDomMap RAssocl))) (RProdMap (RDomMap RAssocr) RId)) (RProdMap RId (RDomMap RAssocr))) (RProdMap RId (RDomMap RAssocr))) (RProdMap RId FST)) SND) SND) SND) SND) SND) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RAnd (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RInc (RComp (RSetMap FST) (RComp RDom SND)) (RComp RDom FST)) (RProdMap RId (RRngMap RMap2List))) (RProdMap RId RMapFuse1)) (RProdMap RId (RProdMap (RDomMap RAssocl) RId))) (RProdMap RId (RProdMap RId (RDomMap RAssocl)))) (RProdMap RId (RProdMap RId (RDomMap RAssocl)))) RSwap) (RProdMap (RProdMap (RDomMap RAssocr) RId) RId)) (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) (RProdMap RId FST)) SND) SND) SND) SND) SND) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RAnd (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RInc (RComp (RSetMap FST) (RComp RDom SND)) (RComp RDom FST)) (RProdMap RId (RDomMap RAssocl))) (RProdMap RId (RDomMap RAssocr))) (RProdMap RId FST)) SND) SND) SND) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RAnd (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RInc (RComp RDom (RComp FST SND)) (RComp RDom FST)) (RProdMap (RRngMap RMap2List) RId)) (RProdMap RMapFuse1 RId)) (RProdMap RId (RProdMap (RRngMap (RProdMap RMap2List RId)) RId))) (RProdMap RId (RProdMap RId RMapFuse1))) (RProdMap RId (RProdMap RId (RProdMap RId (RRngMap RMap2List))))) (RProdMap RId (RProdMap RId (RProdMap RId RMapFuse1)))) (RProdMap (RProdMap RId (RDomMap RAssocl)) RId)) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap (RDomMap RAssocl) RId))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RDomMap RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RDomMap RAssocl)))))) (RProdMap RId RSwap)) (RProdMap RId (RProdMap RSwap RId))) (RProdMap RId (RProdMap RId (RRngMap RSwap)))) RAssocr) (RProdMap (RProdMap (RProdMap RId (RDomMap RAssocr)) RId) RId)) (RProdMap (RProdMap RId (RProdMap (RProdMap (RDomMap RAssocr) RId) RId)) RId)) (RProdMap (RProdMap RId (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) RId)) (RProdMap (RProdMap RId (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) RId)) (RProdMap RId RMapFuse2)) SND) SND) SND) (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))) (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RAnd (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RInc (RComp RDom (RComp SND SND)) (RComp RDom FST)) (RProdMap (RRngMap RMap2List) RId)) (RProdMap RMapFuse1 RId)) (RProdMap RId (RProdMap (RRngMap (RProdMap RMap2List RId)) RId))) (RProdMap RId (RProdMap RId RMapFuse1))) (RProdMap RId (RProdMap RId (RProdMap RId (RRngMap RMap2List))))) (RProdMap RId (RProdMap RId (RProdMap RId RMapFuse1)))) (RProdMap (RProdMap RId (RDomMap RAssocl)) RId)) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap (RDomMap RAssocl) RId))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RDomMap RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RDomMap RAssocl)))))) (RProdMap RId RSwap)) (RProdMap RId (RProdMap RSwap RId))) (RProdMap RId (RProdMap RId (RRngMap RSwap)))) RAssocr) (RProdMap (RProdMap (RProdMap RId (RDomMap RAssocr)) RId) RId)) (RProdMap (RProdMap RId (RProdMap (RProdMap (RDomMap RAssocr) RId) RId)) RId)) (RProdMap (RProdMap RId (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) RId)) (RProdMap (RProdMap RId (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) RId)) (RProdMap RId RMapFuse2)) SND) SND) SND) (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))) (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RAnd (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RInc (RComp (RSetMap FST) (RComp RDom SND)) (RComp RDom FST)) (RProdMap (RDomMap (RProdMap RId RAssocl)) RId)) (RProdMap RId (RDomMap RAssocl))) (RProdMap RId (RDomMap (RProdMap RId RAssocl)))) (RProdMap RId (RDomMap (RProdMap RId RAssocl)))) (RProdMap (RDomMap RAssocr) RId)) (RProdMap (RDomMap RAssocr) RId)) (RProdMap RId (RDomMap RAssocr))) (RProdMap RId (RDomMap RAssocr))) (RProdMap RId (RDomMap RAssocr))) (RProdMap RId FST)) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))) (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RAnd (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RInc (RComp (RSetMap FST) (RComp RDom SND)) (RComp RDom FST)) (RProdMap RId (RRngMap RMap2List))) (RProdMap RId RMapFuse1)) (RProdMap RId (RProdMap (RDomMap (RProdMap RId RAssocl)) RId))) (RProdMap RId (RProdMap RId (RDomMap RAssocl)))) (RProdMap RId (RProdMap RId (RDomMap (RProdMap RId RAssocl))))) (RProdMap RId (RProdMap RId (RDomMap (RProdMap RId RAssocl))))) RSwap) (RProdMap (RProdMap (RDomMap RAssocr) RId) RId)) (RProdMap (RProdMap (RDomMap RAssocr) RId) RId)) (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) (RProdMap RId FST)) RAssocl) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))) (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RInc (RComp (RSetMap FST) (RComp RFuse (RComp (RSetMap RDom) (RComp RRng FST)))) (RComp RDom SND)) (RProdMap RMapFuse1 RId)) (RProdMap (RProdMap RId (RRngMap RMap2List)) RId)) (RProdMap (RProdMap RId RMapFuse1) RId)) (RProdMap RId RCoUnMapsum2)) (RProdMap RId (RProdMap (RRngMap RMap2List) RId))) (RProdMap RId (RProdMap RMapFuse1 RId))) (RProdMap RId (RProdMap RId (RProdMap (RRngMap (RProdMap RMap2List RId)) RId)))) (RProdMap RId (RProdMap RId (RProdMap RId RMapFuse1)))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RRngMap RMap2List)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RMapFuse1))))) (RProdMap (RProdMap RId (RProdMap (RDomMap (RProdMap RId RAssocl)) RId)) RId)) (RProdMap (RProdMap RId (RProdMap RId (RDomMap RAssocl))) RId)) (RProdMap (RProdMap RId (RProdMap RId (RDomMap (RProdMap RId RAssocl)))) RId)) (RProdMap (RProdMap RId (RProdMap RId (RDomMap (RProdMap RId RAssocl)))) RId)) (RProdMap RId (RProdMap (RProdMap RId (RDomMap RAssocl)) RId))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap (RDomMap RAssocl) RId)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RDomMap RAssocl))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RDomMap RAssocl))))))) (RProdMap RSwap RId)) (RProdMap RId (RProdMap RId RSwap))) (RProdMap RId (RProdMap RId (RProdMap RSwap RId)))) (RProdMap RId (RProdMap RId (RProdMap RId (RRngMap RSwap))))) (RProdMap (RProdMap (RProdMap (RDomMap RAssocr) RId) RId) RId)) (RProdMap (RProdMap (RProdMap (RDomMap RAssocr) RId) RId) RId)) (RProdMap (RProdMap (RProdMap RId (RDomMap RAssocr)) RId) RId)) (RProdMap (RProdMap (RProdMap RId (RDomMap RAssocr)) RId) RId)) (RProdMap (RProdMap (RProdMap RId (RDomMap RAssocr)) RId) RId)) (RProdMap RId RAssocr)) (RProdMap RId (RProdMap (RProdMap (RProdMap RId (RDomMap RAssocr)) RId) RId))) (RProdMap RId (RProdMap (RProdMap RId (RProdMap (RProdMap (RDomMap RAssocr) RId) RId)) RId))) (RProdMap RId (RProdMap (RProdMap RId (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) RId))) (RProdMap RId (RProdMap (RProdMap RId (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) RId))) (RProdMap RId (RProdMap RId RMapFuse2))) RAssocl) RAssocl) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))) (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId))))))))))


imdbRelNoSimplify' = (TInv (Prod t1 (Prod t2 (Prod t3 (Prod t4 (Prod t5 (Prod t6 (Prod t7 (Prod t8 (Prod t9 t10))))))))) (RAnd fk1 (RAnd fk2 (RAnd fk3 (RAnd fk4 (RAnd fk5 (RAnd fk6 (RAnd fk7 (RAnd fk8 fk9)))))))))
   where t1  = (Map (Prod (Prod (Prod (TVar "Name" ) (TVar "Year" )) (TVar "Title" )) (TVar "Role" )) One)
         t2  = (Map (Prod (Prod (Prod (Prod (TVar "Name" ) (TVar "Year" )) (TVar "Title" )) (TVar "Role" )) Int) (TVar "Award" ))
         t3  = (Map (TVar "Name" ) One)
         t4  = (Map (Prod (TVar "Year" ) (TVar "Title" )) One)
         t5  = (Map (Prod (Prod (TVar "Year" ) (TVar "Title" )) Int) (TVar "Review" ))
         t6  = (Map (Prod (Prod (TVar "Year" ) (TVar "Title" )) (TVar "Year" )) One)
         t7  = (Map (Prod (Prod (Prod (TVar "Year" ) (TVar "Title" )) (TVar "Year" )) Int) (Prod (TVar "Number" ) (Maybe (TVar "Director" ))))
         t8  = (Map (Prod (TVar "Year" ) (TVar "Title" )) One)
         t9  = (Map (Prod (TVar "Year" ) (TVar "Title" )) (TVar "Director" ))
         t10 = (Map (Prod (Prod (TVar "Year" ) (TVar "Title" )) Int) (Prod (TVar "Country" ) (TVar "Value" )))
         fk1 = (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RInc (RComp (RSetMap FST) (RComp RDom SND)) (RComp RDom FST)) SND) SND) SND) SND) SND) SND) SND) SND)
         fk2 = (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RInc (RComp (RSetMap FST) (RComp RDom SND)) (RComp RDom FST)) (RProdMap (RDomMap RAssocl) RId)) (RProdMap RId (RDomMap RAssocl))) (RProdMap RId (RDomMap RAssocl))) (RProdMap (RDomMap RAssocr) RId)) (RProdMap RId (RDomMap RAssocr))) (RProdMap RId (RDomMap RAssocr))) (RProdMap RId FST)) SND) SND) SND) SND) SND) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId)
         fk3 = (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RInc (RComp (RSetMap FST) (RComp RDom SND)) (RComp RDom FST)) (RProdMap RId (RRngMap RMap2List))) (RProdMap RId RMapFuse1)) (RProdMap RId (RProdMap (RDomMap RAssocl) RId))) (RProdMap RId (RProdMap RId (RDomMap RAssocl)))) (RProdMap RId (RProdMap RId (RDomMap RAssocl)))) RSwap) (RProdMap (RProdMap (RDomMap RAssocr) RId) RId)) (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) (RProdMap RId FST)) SND) SND) SND) SND) SND) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId)
         fk4 = (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RInc (RComp (RSetMap FST) (RComp RDom SND)) (RComp RDom FST)) (RProdMap RId (RDomMap RAssocl))) (RProdMap RId (RDomMap RAssocr))) (RProdMap RId FST)) SND) SND) SND) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId)
         fk5 = (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RInc (RComp RDom (RComp FST SND)) (RComp RDom FST)) (RProdMap (RRngMap RMap2List) RId)) (RProdMap RMapFuse1 RId)) (RProdMap RId (RProdMap (RRngMap (RProdMap RMap2List RId)) RId))) (RProdMap RId (RProdMap RId RMapFuse1))) (RProdMap RId (RProdMap RId (RProdMap RId (RRngMap RMap2List))))) (RProdMap RId (RProdMap RId (RProdMap RId RMapFuse1)))) (RProdMap (RProdMap RId (RDomMap RAssocl)) RId)) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap (RDomMap RAssocl) RId))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RDomMap RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RDomMap RAssocl)))))) (RProdMap RId RSwap)) (RProdMap RId (RProdMap RSwap RId))) (RProdMap RId (RProdMap RId (RRngMap RSwap)))) RAssocr) (RProdMap (RProdMap (RProdMap RId (RDomMap RAssocr)) RId) RId)) (RProdMap (RProdMap RId (RProdMap (RProdMap (RDomMap RAssocr) RId) RId)) RId)) (RProdMap (RProdMap RId (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) RId)) (RProdMap (RProdMap RId (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) RId)) (RProdMap RId RMapFuse2)) SND) SND) SND) (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))) (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId)
         fk6 = (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RInc (RComp RDom (RComp SND SND)) (RComp RDom FST)) (RProdMap (RRngMap RMap2List) RId)) (RProdMap RMapFuse1 RId)) (RProdMap RId (RProdMap (RRngMap (RProdMap RMap2List RId)) RId))) (RProdMap RId (RProdMap RId RMapFuse1))) (RProdMap RId (RProdMap RId (RProdMap RId (RRngMap RMap2List))))) (RProdMap RId (RProdMap RId (RProdMap RId RMapFuse1)))) (RProdMap (RProdMap RId (RDomMap RAssocl)) RId)) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap (RDomMap RAssocl) RId))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RDomMap RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RDomMap RAssocl)))))) (RProdMap RId RSwap)) (RProdMap RId (RProdMap RSwap RId))) (RProdMap RId (RProdMap RId (RRngMap RSwap)))) RAssocr) (RProdMap (RProdMap (RProdMap RId (RDomMap RAssocr)) RId) RId)) (RProdMap (RProdMap RId (RProdMap (RProdMap (RDomMap RAssocr) RId) RId)) RId)) (RProdMap (RProdMap RId (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) RId)) (RProdMap (RProdMap RId (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) RId)) (RProdMap RId RMapFuse2)) SND) SND) SND) (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))) (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId)
         fk7 = (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RInc (RComp (RSetMap FST) (RComp RDom SND)) (RComp RDom FST)) (RProdMap (RDomMap (RProdMap RId RAssocl)) RId)) (RProdMap RId (RDomMap RAssocl))) (RProdMap RId (RDomMap (RProdMap RId RAssocl)))) (RProdMap RId (RDomMap (RProdMap RId RAssocl)))) (RProdMap (RDomMap RAssocr) RId)) (RProdMap (RDomMap RAssocr) RId)) (RProdMap RId (RDomMap RAssocr))) (RProdMap RId (RDomMap RAssocr))) (RProdMap RId (RDomMap RAssocr))) (RProdMap RId FST)) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))) (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId)
         fk8 = (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RInc (RComp (RSetMap FST) (RComp RDom SND)) (RComp RDom FST)) (RProdMap RId (RRngMap RMap2List))) (RProdMap RId RMapFuse1)) (RProdMap RId (RProdMap (RDomMap (RProdMap RId RAssocl)) RId))) (RProdMap RId (RProdMap RId (RDomMap RAssocl)))) (RProdMap RId (RProdMap RId (RDomMap (RProdMap RId RAssocl))))) (RProdMap RId (RProdMap RId (RDomMap (RProdMap RId RAssocl))))) RSwap) (RProdMap (RProdMap (RDomMap RAssocr) RId) RId)) (RProdMap (RProdMap (RDomMap RAssocr) RId) RId)) (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) (RProdMap RId FST)) RAssocl) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))) (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId)
         fk9 = (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RInc (RComp (RSetMap FST) (RComp RFuse (RComp (RSetMap RDom) (RComp RRng FST)))) (RComp RDom SND)) (RProdMap RMapFuse1 RId)) (RProdMap (RProdMap RId (RRngMap RMap2List)) RId)) (RProdMap (RProdMap RId RMapFuse1) RId)) (RProdMap RId RCoUnMapsum2)) (RProdMap RId (RProdMap (RRngMap RMap2List) RId))) (RProdMap RId (RProdMap RMapFuse1 RId))) (RProdMap RId (RProdMap RId (RProdMap (RRngMap (RProdMap RMap2List RId)) RId)))) (RProdMap RId (RProdMap RId (RProdMap RId RMapFuse1)))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RRngMap RMap2List)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RMapFuse1))))) (RProdMap (RProdMap RId (RProdMap (RDomMap (RProdMap RId RAssocl)) RId)) RId)) (RProdMap (RProdMap RId (RProdMap RId (RDomMap RAssocl))) RId)) (RProdMap (RProdMap RId (RProdMap RId (RDomMap (RProdMap RId RAssocl)))) RId)) (RProdMap (RProdMap RId (RProdMap RId (RDomMap (RProdMap RId RAssocl)))) RId)) (RProdMap RId (RProdMap (RProdMap RId (RDomMap RAssocl)) RId))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap (RDomMap RAssocl) RId)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RDomMap RAssocl))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RDomMap RAssocl))))))) (RProdMap RSwap RId)) (RProdMap RId (RProdMap RId RSwap))) (RProdMap RId (RProdMap RId (RProdMap RSwap RId)))) (RProdMap RId (RProdMap RId (RProdMap RId (RRngMap RSwap))))) (RProdMap (RProdMap (RProdMap (RDomMap RAssocr) RId) RId) RId)) (RProdMap (RProdMap (RProdMap (RDomMap RAssocr) RId) RId) RId)) (RProdMap (RProdMap (RProdMap RId (RDomMap RAssocr)) RId) RId)) (RProdMap (RProdMap (RProdMap RId (RDomMap RAssocr)) RId) RId)) (RProdMap (RProdMap (RProdMap RId (RDomMap RAssocr)) RId) RId)) (RProdMap RId RAssocr)) (RProdMap RId (RProdMap (RProdMap (RProdMap RId (RDomMap RAssocr)) RId) RId))) (RProdMap RId (RProdMap (RProdMap RId (RProdMap (RProdMap (RDomMap RAssocr) RId) RId)) RId))) (RProdMap RId (RProdMap (RProdMap RId (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) RId))) (RProdMap RId (RProdMap (RProdMap RId (RProdMap (RProdMap RId (RDomMap RAssocr)) RId)) RId))) (RProdMap RId (RProdMap RId RMapFuse2))) RAssocl) RAssocl) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))) (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RAssocl)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId)))))) (RProdMap RId (RProdMap RId (RProdMap RId (RProdMap RId RId))))) (RProdMap RId (RProdMap RId (RProdMap RId RId)))) (RProdMap RId (RProdMap RId RId))) (RProdMap RId RId)) RId)
    


imdbRelSimplified = TInv (Prod (Map (Prod (Prod (Prod (TVar "Name" ) (TVar "Year" )) (TVar "Title" )) (TVar "Role" )) One) (Prod (Map (Prod (Prod (Prod (Prod (TVar "Name" ) (TVar "Year" )) (TVar "Title" )) (TVar "Role" )) Int) (TVar "Award" )) (Prod (Map (TVar "Name" ) One) (Prod (Map (Prod (TVar "Year" ) (TVar "Title" )) One) (Prod (Map (Prod (Prod (TVar "Year" ) (TVar "Title" )) Int) (TVar "Review" )) (Prod (Map (Prod (Prod (TVar "Year" ) (TVar "Title" )) (TVar "Year" )) One) (Prod (Map (Prod (Prod (Prod (TVar "Year" ) (TVar "Title" )) (TVar "Year" )) Int) (Prod (TVar "Number" ) (Maybe (TVar "Director" )))) (Prod (Map (Prod (TVar "Year" ) (TVar "Title" )) One) (Prod (Map (Prod (TVar "Year" ) (TVar "Title" )) (TVar "Director" )) (Map (Prod (Prod (TVar "Year" ) (TVar "Title" )) Int) (Prod (TVar "Country" ) (TVar "Value" )))))))))))) (RAnd (RInc (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RSetMap FST) (RComp RDom SND)) SND) SND) SND) SND) SND) SND) SND) SND) (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp RDom FST) SND) SND) SND) SND) SND) SND) SND) SND)) (RAnd (RInc (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RSetMap FST) RDom) FST) SND) SND) SND) SND) SND) SND) (RComp RDom (RComp (RComp (RComp (RComp (RComp FST SND) SND) SND) SND) SND))) (RAnd (RInc (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RSetMap FST) RDom) FST) SND) SND) SND) SND) SND) (RComp RDom (RComp FST (RComp (RComp (RComp (RComp (RComp (RComp SND SND) SND) SND) SND) SND) SND)))) (RAnd (RInc (RComp (RComp (RComp (RComp (RComp (RComp (RSetMap FST) RDom) FST) SND) SND) SND) SND) (RComp RDom (RComp (RComp (RComp FST SND) SND) SND))) (RAnd (RInc (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp RDom FST) SND) SND) SND) SND) SND) SND) SND) SND) (RComp RDom (RComp (RComp (RComp FST SND) SND) SND))) (RAnd (RInc (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp RDom FST) SND) SND) SND) SND) SND) SND) SND) (RComp RDom (RComp (RComp (RComp FST SND) SND) SND))) (RAnd (RInc (RComp (RComp (RComp (RSetMap (RComp (RComp (RComp (RProdMap RId (RComp (RProdMap RId FST) RAssocl)) RAssocr) RAssocr) RAssocr)) RDom) FST) SND) (RComp (RComp (RSetMap (RComp (RComp (RProdMap RId RAssocl) RAssocr) RAssocr)) RDom) FST)) (RAnd (RInc (RComp (RComp (RSetMap (RComp (RComp FST FST) FST)) RDom) FST) (RComp RDom (RComp (RComp FST SND) SND))) (RInc (RComp (RComp (RSetMap (RComp (RProdMap SND RId) FST)) RDom) FST) (RComp RDom (RComp (RComp (RComp FST SND) SND) SND)))))))))))


imdbRelSimplified'
   = TInv (Prod t1 (Prod t2 (Prod t3 (Prod t4 (Prod t5 (Prod t6 (Prod t7 (Prod t8 (Prod t9 t10))))))))) (RAnd fk1 (RAnd fk2 (RAnd fk3 (RAnd fk4 (RAnd fk5 (RAnd fk6 (RAnd fk7 (RAnd fk8 fk9))))))))
   where t1  = Map (Prod (Prod (Prod (TVar "Name" ) (TVar "Year" )) (TVar "Title" )) (TVar "Role" )) One 
         t2  = Map (Prod (Prod (Prod (Prod (TVar "Name" ) (TVar "Year" )) (TVar "Title" )) (TVar "Role" )) Int) (TVar "Award" )
         t3  = Map (TVar "Name" ) One
         t4  = Map (Prod (TVar "Year" ) (TVar "Title" )) One
         t5  = Map (Prod (Prod (TVar "Year" ) (TVar "Title" )) Int) (TVar "Review" )
         t6  = Map (Prod (Prod (TVar "Year" ) (TVar "Title" )) (TVar "Year" )) One
         t7  = Map (Prod (Prod (Prod (TVar "Year" ) (TVar "Title" )) (TVar "Year" )) Int) (Prod (TVar "Number" ) (Maybe (TVar "Director" )))
         t8  = Map (Prod (TVar "Year" ) (TVar "Title" )) One
         t9  = Map (Prod (TVar "Year" ) (TVar "Title" )) (TVar "Director" )
         t10 = Map (Prod (Prod (TVar "Year" ) (TVar "Title" )) Int) (Prod (TVar "Country" ) (TVar "Value" ))
         fk1 = RInc (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RSetMap FST) (RComp RDom SND)) SND) SND) SND) SND) SND) SND) SND) SND) 
                    (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp RDom FST) SND) SND) SND) SND) SND) SND) SND) SND)
         fk2 = RInc (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RSetMap FST) RDom) FST) SND) SND) SND) SND) SND) SND) 
                    (RComp RDom (RComp (RComp (RComp (RComp (RComp FST SND) SND) SND) SND) SND))
         fk3 = RInc (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RSetMap FST) RDom) FST) SND) SND) SND) SND) SND) 
                    (RComp RDom (RComp FST (RComp (RComp (RComp (RComp (RComp (RComp SND SND) SND) SND) SND) SND) SND)))
         fk4 = RInc (RComp (RComp (RComp (RComp (RComp (RComp (RSetMap FST) RDom) FST) SND) SND) SND) SND) 
                    (RComp RDom (RComp (RComp (RComp FST SND) SND) SND))
         fk5 = RInc (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp RDom FST) SND) SND) SND) SND) SND) SND) SND) SND) 
                    (RComp RDom (RComp (RComp (RComp FST SND) SND) SND))
         fk6 = RInc (RComp (RComp (RComp (RComp (RComp (RComp (RComp (RComp RDom FST) SND) SND) SND) SND) SND) SND) SND) 
                    (RComp RDom (RComp (RComp (RComp FST SND) SND) SND))
         fk7 = RInc (RComp (RComp (RComp (RSetMap (RComp (RComp (RComp (RProdMap RId (RComp (RProdMap RId FST) RAssocl)) RAssocr) RAssocr) RAssocr)) RDom) FST) SND) 
                    (RComp (RComp (RSetMap (RComp (RComp (RProdMap RId RAssocl) RAssocr) RAssocr)) RDom) FST)
         fk8 = RInc (RComp (RComp (RSetMap (RComp (RComp FST FST) FST)) RDom) FST) 
                    (RComp RDom (RComp (RComp FST SND) SND))
         fk9 = RInc (RComp (RComp (RSetMap (RComp (RProdMap SND RId) FST)) RDom) FST) 
                    (RComp RDom (RComp (RComp (RComp FST SND) SND) SND))



result = putStrLn $ showDB [ "playeds", "awards" , "actors", "shows", "reviews", "seasons", "episodes", "series", "movies", "boxoffices" ] imdbRelSimplified

-}
